import { Button, Popconfirm } from 'antd';
import React, { useState } from 'react';
import { useLocation } from 'react-router';

const authorityButton = (props) => {
  // eslint-disable-next-line react-hooks/rules-of-hooks
  const location = useLocation();
  const ac = localStorage.getItem('token');
  console.log('这是路由' + JSON.stringify(location));
  const IsShow = (className) => {
    return true;
    if (className == 'Add') {
      return true;
    } else {
      return false;
    }
  };


  if (props.type == 'popconfirm') {
    return (
      <Popconfirm
        type="primary"
        key="primary"
        title="确认删除吗？"
        okText="是"
        cancelText="否"
        onConfirm={props.onConfirm}
        onCancel={props.onCancel}
        disabled={props.disabled}
        style={{ display: IsShow(props.class) ? 'inline' : 'none' }}
      >
        <a href="#"> {props.text}</a>
      </Popconfirm >);
  }
  if (props.type == 'link') {
    return (
      <a
        onClick={props.onClick}
        icon={props.icon}
        disabled={props.disabled}
        style={{ display: IsShow(props.class) ? 'inline' : 'none' }}
      >
        {props.text}
      </a>
    );
  } else {
    return (
      <Button
        type={'primary'}
        onClick={props.onClick}
        icon={props.icon}
        disabled={props.disabled}
        style={{ display: IsShow(props.class) ? 'inline' : 'none' }}
      >
        {props.text}
      </Button>
    );
  }
};
export default authorityButton;
